const app = getApp();
import {request} from '../../utils/request'
import config from '../../utils/config'

Page({
    data: {
        picUrl: config.picUrl,
        path: '/pages/good_list_ranking/good_list',
        goodList:[],
        type: 0,
        order:'all',//排序方式：all-综合；hot-热门；sales-销量；new-上新
        is_new:1,
        sku:[],
        page:1,
        last_page:1,
        endHide:true,
        custom: {top:null,bottom:null,height:null,left:null,right:null,width:null},
        banner:{},
        ticaiList:[],
        navIndex:0,
    },
    onLoad(options) {
        this.setData({
            path: this.data.path,
            custom: wx.getMenuButtonBoundingClientRect()
        })
        this.getList()
        this.getBanner()
        this.getTicai()
    },
    getBanner(){
        request({
            url:'/miniprogram/system/getBanners',
            data:{path:this.data.path}
        }).then(res=>{
            this.setData({banner:res.data[0]})
        })
    },
    changeType(e){
        var {id,index} = e.currentTarget.dataset
        this.setData({navIndex:index,type:id})
        this.getList()
    },
    getList() {
        request({
            url:"/miniprogram/good/getOneBang",
            data:{
                type:this.data.type,
                page:this.data.page,
            },
            type:'post'
        }).then(res=>{
            if(res.code !== 0){
                wx.showToast({title:res.msg,icon:'none'})
                return false
            }
            if(this.data.page == 1){
                this.setData({goodList:[]})
            }
            this.setData({
                goodList:this.data.goodList.concat(res.data),
                last_page:res.last_page
            })
        })
    },
    getTicai(){
        request({
            url:'/miniprogram/system/getTicai',
        }).then(res=>{
            this.setData({ticaiList:res.data})
        })
    },
    onOpen(e) {
        this.setData({opened: true})
    },
    onClose(e) {
        this.setData({opened: false})
    },
    changeNew(e){
        this.setData({is_new:e.currentTarget.dataset.new,page:1,endHide:true})
        this.getList()
    },
    changeOrder(e){
        this.setData({order:e.currentTarget.dataset.order,page:1,endHide:true})
        this.getList()
    },
    /**
     * 阻止触摸移动
     */
    back() {
        wx.navigateBack({delta:1})
    },
    onPullDownRefresh() {
    },
    onReachBottom() {
    },
    onShareAppMessage() {
    },
    naviGood(e){
        var info = wx.getStorageSync('userInfo')
        //authentication_type 认证类型3-发行商，4-商户，5-普通访客
        //is_authentication 是否经过系统认证，0-未认证；1-审核中；2-审核通过；3-审核被拒
        if(info.is_wechat_authentication != 1){
            wx.showModal({
                title:'提示',
                content:"您还未登录或注册，请先登录",
                cancelText:"取消",
                confirmText:"登录",
                success:res=>{
                    if(res.confirm){
                        wx.switchTab({url:"/pages/my/my"})
                    }else{

                    }
                }
            })
            return false
        }
        if(info.authentication_type == 5){
            wx.showModal({
                title:'提示',
                content:"您还未进行身份认证，请先认证您身份信息",
                cancelText:"认证商户",
                confirmColor:"#000",
                confirmText:"认证发行",
                success:res=>{
                    if(res.confirm){
                        wx.navigateTo({url:"/pages/faxingrenzheng/faxingrenzheng"})
                    }else{
                        wx.navigateTo({url:"/pages/shanghurenzheng/shanghurenzheng"})
                    }
                }
            })
            return false;
        }
        if(info.is_authentication != 2){
            config.toast("您的身份审核暂未通过，请等待审核通过",201,()=>{})
            return false
        }
        wx.navigateTo({url:e.currentTarget.dataset.url})
    },
})